package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.PropertyPaymentPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertySaveMeterInfoDTO;
import com.itlong.cloud.POJO.VO.property.PropertyGetManagementPageVO;
import com.itlong.cloud.POJO.VO.property.PropertyGetMeterInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyPaymentGetPageVO;
import com.itlong.cloud.project.property.IPropertyPaymentManageServiceClient;
import com.itlong.cloud.property.service.IPropertyPaymentManageService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * <desc>
 *      物业收费管理暴露接口实现类
 * </desc>
 *
 * @createDate 2018/08/15
 */
@RestController
public class PropertyPaymentManageServiceResource implements IPropertyPaymentManageServiceClient{
    @Autowired
    IPropertyPaymentManageService iPropertyPaymentManageService;

    /**
     * <desc>
     *      获取分页数据
     * </desc>
     *
     * @param pageDTO   参数DTO
     * @return
     * @author Jiaqi.X
     * @createDate 2017/09/27
     */
    @RequestMapping(path = "/expenses/copymeter/getMeterInfoByPage")
    @Override
    public Page<PropertyPaymentGetPageVO> getMeterInfoByPage(@RequestBody PropertyPaymentPageDTO pageDTO) throws Exception {
        return iPropertyPaymentManageService.getMeterInfoByPage(pageDTO);
    }

    /**
     * <desc>
     *      保存或修改抄表、物业费数据
     * </desc>
     *
     * @param dto
     * @return
     * @author Jiaqi.X
     * @createDate 2018/08/17
     */
    @PostMapping(path = "/expenses/copymeter/saveOrUpdateMemterInfo")
    public String saveOrUpdateMemterInfo(@RequestBody PropertySaveMeterInfoDTO dto) throws Exception {
        return iPropertyPaymentManageService.saveOrUpdateMemterInfo(dto);
    }

    /**
     * <desc>
     *      删除录入数据
     * </desc>
     *
     * @param feeDataId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/08/20
     */
    @Override
    @PostMapping(path = "/expenses/copymeter/deletePaymentRecord")
    public Integer deletePaymentRecord(@RequestParam("feeDataId") String feeDataId) throws Exception {
        return iPropertyPaymentManageService.deletePaymentRecord(feeDataId);
    }

    /**
     * <desc>
     *      批量生成抄表费或物业费数据
     * </desc>
     *
     * @param buildIds 楼栋id,多个逗号分隔
     * @param type 1抄表费 2物业费
     * @param month 收费月份
     * @return
     * @author Jiaqi.X
     * @createDate 2018/08/22
     */
    @Override
    @PostMapping(path = "/expenses/copymeter/batchAddPaymentRecord")
    public Integer batchAddPaymentRecord(@RequestParam("buildIds") String buildIds,
                                         @RequestParam("type") Integer type,
                                         @RequestParam("month") String month) throws ParseException {
        return iPropertyPaymentManageService.batchAddPaymentRecord(buildIds,type,month);
    }

    /**
     * <desc>
     *      根据id查询抄表费或物业费
     * </desc>
     *
     * @param feeDataId
     * @param type 1抄表费 2物业费
     * @return
     * @author Jiaqi.X
     * @createDate 2018/08/21
     */
    @Override
    public PropertyGetMeterInfoVO getPaymentInfoById(@RequestParam("feeDataId") String feeDataId, @RequestParam("type") String type) {
        return iPropertyPaymentManageService.getPaymentInfoById(feeDataId,type);
    }

    /**
     * <desc>
     *     获取物业费分页数据
     * </desc>
     *
     * @param pageDTO   参数DTO
     * @return
     * @author Jiaqi.X
     * @createDate 2018/08/20
     */
    @Override
    public Page<PropertyGetManagementPageVO> getManagementInfoByPage(@RequestBody PropertyPaymentPageDTO pageDTO) throws Exception {
        return iPropertyPaymentManageService.getManagementInfoByPage(pageDTO);
    }


    /**
     * <desc>
     *      导入物业费数据
     * </desc>
     *
     * @param propertySaveMeterInfoDTOs
     * @author  Jiaqi.X
     * @createDate 2018/08/30
     */
    @Override
    @PostMapping(path = "/expenses/copymeter/importSavePropertyFees")
    public void importSavePropertyFees(@RequestBody List<PropertySaveMeterInfoDTO> propertySaveMeterInfoDTOs) throws Exception {
        iPropertyPaymentManageService.importSavePropertyFees(propertySaveMeterInfoDTOs);
    }

    /**
     * <desc>
     *      导入抄表费
     * </desc>
     *
     * @param propertySaveMeterInfoDTOs
     * @author Jiaqi.X
     * @createDate 2018/08/30
     */
    @PostMapping(path = "/expenses/copymeter/importSaveMeterInfoFees")
    @Override
    public String importSaveMeterInfoFees(@RequestBody List<PropertySaveMeterInfoDTO> propertySaveMeterInfoDTOs) throws Exception {
        return iPropertyPaymentManageService.importSaveMeterInfoFees(propertySaveMeterInfoDTOs);
    }

    /**
     * <desc>
     *      检测当前房间是否有业主
     * </desc>
     *
     * @param roomId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/03
     */
    @PostMapping(path = "/expenses/copymeter/checkRoomHaveOwner")
    @Override
    public Integer checkRoomHaveOwner(@RequestParam("roomId") String roomId){
        return iPropertyPaymentManageService.checkRoomHaveOwner(roomId);
    }

    /**
     * <desc>
     *      检查房间是否存在
     * </desc>
     *
     * @param address
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/03
     */
    @PostMapping(path = "/expenses/copymeter/checkRoomExists")
    public Integer checkRoomExists(@RequestParam("address") String address,@RequestParam("projectId") String projectId){
        return iPropertyPaymentManageService.checkRoomExists(address,projectId);
    }

    /**
     * <desc>
     *      检查收费规则是否存在
     * </desc>
     *
     * @param projectId 项目id
     * @param ruleName 规则名称
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/03
     */
    @PostMapping(path = "/expenses/copymeter/checkRuleIsExists")
    @Override
    public boolean checkRuleIsExists(@RequestParam("projectId") String projectId,@RequestParam("ruleName") String ruleName,@RequestParam("type") Integer type){
        return iPropertyPaymentManageService.checkRuleIsExists(projectId,ruleName,type);
    }

    /**
     * <desc>
     *      检测导入数据的规则是否合法
     * </desc>
     *
     * @param roomName
     * @param ruleName
     * @param type 1抄表费 2物业费
     * @return
     * @author Jiaqi.X
     * @createDate 2018/10/17
     */
    @PostMapping(path = "/expenses/copymeter/checkImportDataRuleTime")
    @Override
    public Integer checkImportDataRuleTime(@RequestParam("roomName") String roomName,
                                           @RequestParam("ruleName") String ruleName,
                                           @RequestParam("type") Integer type,
                                           @RequestParam("projectId") String projectId,
                                           @RequestParam("month") String month) throws ParseException{
        return iPropertyPaymentManageService.checkImportDataRuleTime(roomName,ruleName,type,projectId,month);
    }

    /**
     * <desc>
     *      检测房间面积是否为空
     * </desc>
     *
     * @param roomId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/10/23
     */
    @PostMapping(path = "/expenses/copymeter/checkRoomArea")
    public Integer checkRoomArea(@RequestParam("roomId") String roomId){
        return iPropertyPaymentManageService.checkRoomArea(roomId);
    }
}
